﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Model;
using MySql.Data.MySqlClient;

namespace DAL
{
    public class diskDal
    {
        /// <summary>
        /// 添加桌子
        /// </summary>
        /// <param name="merchantid"></param>
        /// <param name="disknmae"></param>
        /// <param name="person"></param>
        /// <returns></returns>
        public static int Adddisk(string merchantid, string disknmae, string person)
        {
            string sql = "insert into ms_disk(ds_merchantid,ds_disknmae,ds_person,ds_updatedate) values(@ds_merchantid,@ds_disknmae,@ds_person,@ds_updatedate)";
            MySqlParameter[] values = new MySqlParameter[4];
            values[0] = new MySqlParameter("ds_merchantid", merchantid);
            values[1] = new MySqlParameter("ds_disknmae", disknmae);
            values[2] = new MySqlParameter("ds_person", person);
            values[3] = new MySqlParameter("ds_updatedate", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
            return DBHelper.ExcutUpdate(sql, values);
        }
        /// <summary>
        /// 查商户餐桌信息
        /// </summary>
        /// <param name="merchantid"></param>
        /// <returns></returns>
        public static List<ms_disk> Querybymerid(string merchantid)
        {
            string sql = "select * from ms_disk where ds_merchantid=@ds_merchantid and ds_isdel=1";
            MySqlParameter[] values = new MySqlParameter[1];
            values[0] = new MySqlParameter("ds_merchantid", merchantid);
            List<ms_disk> dislist = new List<ms_disk>();
            MySqlDataReader rd = DBHelper.ExcutQuery(sql, values);
            while (rd.Read())
            {
                ms_disk disk = new ms_disk();
                disk.ds_id = rd["ds_id"].ToString();
                disk.ds_merchantid = rd["ds_merchantid"].ToString();
                disk.ds_disknmae = rd["ds_disknmae"].ToString();
                disk.ds_person = rd["ds_person"].ToString();
                dislist.Add(disk);
            }
            rd.Close();
            return dislist;
        }
        /// <summary>
        /// 更新信息
        /// </summary>
        /// <param name="diskid"></param>
        /// <param name="disknmae"></param>
        /// <param name="person"></param>
        /// <returns></returns>
        public static int Updatedisk(string diskid, string disknmae, string person)
        {
            string sql = "update ms_disk set ds_disknmae=@ds_disknmae,ds_person=@ds_person,ds_updatedate=@ds_updatedate where ds_id=@ds_id";
            MySqlParameter[] values = new MySqlParameter[4];
            values[0] = new MySqlParameter("ds_id", diskid);
            values[1] = new MySqlParameter("ds_disknmae", disknmae);
            values[2] = new MySqlParameter("ds_person", person);
            values[3] = new MySqlParameter("ds_updatedate", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
            return DBHelper.ExcutUpdate(sql, values);
        }

        /// <summary>
        /// 删除餐桌
        /// </summary>
        /// <param name="diskid"></param>
        /// <returns></returns>
        public static int Deldisk(string diskid)
        {
            string sql = "update ms_disk set ds_isdel=0 where  ds_id=@ds_id";
            MySqlParameter[] values = new MySqlParameter[1];
            values[0] = new MySqlParameter("ds_id", diskid);
            return DBHelper.ExcutUpdate(sql, values);
        }
    }
}
